<?php
/**
 * Created by PhpStorm.
 * User: huynguyen
 * Date: 9/18/14
 * Time: 8:14 PM
 */

namespace Hdphim\Modules\Admin\Forms\VideoCategory;

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Password;
use Phalcon\Forms\Element\Submit;
use Phalcon\Forms\Element\Check;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Email;
use Phalcon\Validation\Validator\Identical;
use Phalcon\Validation\Validator\StringLength;
use Phalcon\Validation\Validator\Confirmation;

class FormCreateVideoCategory extends Form
{
    public function initialize()
    {
        $category = new Text('category' , array(
            'class' => 'form-control col-xs-12',
            'placeholder' => 'category'
        ));

        $category->addValidators(array(
            new PresenceOf(array(
                'message' => 'category is required'
            ))
        ));
        $this->add($category);

        $description = new Text('description' , array(
            'class' => 'form-control col-xs-12',
            'placeholder' => 'category'
        ));

        $this->add($description);

        // CSRF
        $csrf = new Hidden('csrf');

        $csrf->addValidator(new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
        )));

        $this->add($csrf);

        // Sign Up
        $this->add(new Submit('submit', array(
            'class' => 'btn btn-primary'
        )));

    }

    public function messages($name)
    {
        if($this->getMessagesFor($name))
        {
            foreach ($this->getMessagesFor($name) as $message)
            {
                $this->flash->error($message);
            }
        }
    }
} 